﻿using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using UnityEngine;
using UnityEngine.UI;
using RedPointSystem;

public class Main : MonoBehaviour
{
    public Button btn;
    public Transform Content;
    public Button Item;

    // Start is called before the first frame update
    void Start()
    {
        btn.onClick.AddListener(() =>
        {
            ItemSystem.canLevelUpIds.Clear();
            RedPointCheckMgr.GetInstance().CheckByType(100);
        });
    }

    private void InitItems()
    {
        int count = Random.Range(15, 20);
        for (int i = 1; i <= count; ++i)
        {
            var item = Instantiate(Item);
            item.name = i.ToString();
            item.GetComponentInChildren<Text>().text = i.ToString();
            item.GetComponent<RedPoint>().SetConditionByTypeId(100, i);
            item.GetComponent<RedPoint>().SetConditionByTypeId(200, i);
            item.GetComponent<Item>().Refresh(i, (id) =>
            {
                if (ItemSystem.canLevelUpIds.Count > 0)
                {
                    if (ItemSystem.canLevelUpIds.Contains(id))
                    {
                        ItemSystem.canLevelUpIds.Remove(id);
                        RedPointCheckMgr.GetInstance().CheckByType(100);
                    }
                }
                else
                {
                    if (ItemSystem.canStarUpIds.Contains(id))
                    {
                        ItemSystem.canStarUpIds.Remove(id);
                        RedPointCheckMgr.GetInstance().CheckByType(200);
                    }
                }
            });
            
            item.transform.SetParent(Content);
            item.transform.localScale = Vector2.one;
            item.gameObject.SetActive(true);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            InitItems();
        }
    }
}
